package com.isunny.mode.tactics.factory;

import com.isunny.mode.tactics.strategy.EvictionStrategy;
import com.isunny.mode.tactics.EvictionType;
import com.isunny.mode.tactics.strategy.FifoEvictionStrategy;
import com.isunny.mode.tactics.strategy.LfuEvictionStrategy;
import com.isunny.mode.tactics.strategy.LruEvictionStrategy;

import java.util.HashMap;
import java.util.Map;

/**
 * 单例工厂
 *
 * @author luom
 * @date 2022/2/25
 */
public class EvictionStrategySingleFactory {

    private static final Map<EvictionType, EvictionStrategy> EVICTION_STRATEGY_MAP = new HashMap<>();

    static {
        EVICTION_STRATEGY_MAP.put(EvictionType.LRU, new LruEvictionStrategy());
        EVICTION_STRATEGY_MAP.put(EvictionType.LFU, new LfuEvictionStrategy());
        EVICTION_STRATEGY_MAP.put(EvictionType.FIFO, new FifoEvictionStrategy());
    }

    private EvictionStrategySingleFactory() {
    }

    /**
     * 策略工厂
     *
     * @param evictionType 策略字典
     * @return EvictionStrategy
     */
    public static EvictionStrategy getEvictionType(EvictionType evictionType) {
        return EVICTION_STRATEGY_MAP.get(evictionType);
    }
}
